import logging
import sys

def setup_logging():
    """
    设置日志配置
    返回logger对象
    """
    logger = logging.getLogger("ai_drawing_app")
    logger.setLevel(logging.INFO)
    
    # 创建控制台处理器
    handler = logging.StreamHandler(sys.stdout)
    handler.setLevel(logging.INFO)
    
    # 创建格式化器
    formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
    handler.setFormatter(formatter)
    
    # 添加处理器到logger
    logger.addHandler(handler)
    
    return logger

def validate_image_size(width, height, max_width=1024, max_height=1024):
    """
    验证图像尺寸是否有效
    返回验证后的尺寸元组(width, height)
    """
    try:
        w = int(width)
        h = int(height)
        
        # 确保尺寸为正整数
        if w <= 0 or h <= 0:
            return (max_width, max_height)
        
        # 限制最大尺寸
        w = min(w, max_width)
        h = min(h, max_height)
        
        return (w, h)
    except ValueError:
        return (max_width, max_height)